home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
program
/
swagn_r.zip
/
OOP.SWG
/
0024_Passing method as OBJect.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-08-27
|
920b
|
50 lines
{
Stuart Maclean
Hi there, I've found a neat way of passing an Object a method of its own
class, which it then executes. The idea comes from Smalltalk's
change/update mechanism For dependencies under the MVC paradigm.
Works under TP6.
}
Type
DependentPtr = ^Dependent;
Dependent = Object
Procedure Update(p : Pointer);
Procedure SomeMethod;
end;
Model = Object
dep : DependentPtr;
Procedure Change;
end;
Procedure Dependent.Update; Assembler;
Asm
les di, self
push es
push di
call dWord ptr p
end;
Procedure Dependent.SomeMethod;
begin
{ do something here }
end;
Procedure Model.Change;
begin
dep^.Update(@Dependent.Somemethod);
end;
Var
m : Model;
d : Dependent;
begin
m.dep := @d; { add d as a dependent of m }
m.Change; { caUses d to be updated }
end.